<template>
  <div class="flex-1 flex-column h-1">
    <el-table ref="tableBox" :data="tableData" border height="100%" style="width: 100%; height: 100%">
      <template slot="empty">
        <NullData />
      </template>
      <el-table-column :label="$t('SEQUENCE')" align="center" type="index" :width="resetSize(60)">
        <template slot-scope="scope">
          <span>{{ (currentPage - 1) * pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="recordTime" :label="$t('OPERATE_TIME')" width="180" align="left" />
      <el-table-column prop="realName" :label="$t('REAL_NAME')" width="180" align="left" />
      <el-table-column prop="userId" :label="$t('USER_ID')" width="180" align="left" />
      <el-table-column prop="item" :label="$t('OPERATE_ITEM')" align="left">
        <template slot-scope="scope">
          {{ $t(scope.row.item) }}
        </template>
      </el-table-column>
      <el-table-column prop="terminal" :label="$t('OPERATE_COMMAND')" align="left">
        <template slot-scope="scope">
          {{ $t(scope.row.terminal) }}
        </template>
      </el-table-column>
      <el-table-column prop="object" :label="$t('OPERATE_OBJECT')" align="left">
        <template slot-scope="scope">
          {{ $t(scope.row.object) }}
        </template>
      </el-table-column>
      <el-table-column prop="content" :label="$t('OPERATE_CONTENT')" align="left" min-width="350">
        <template slot-scope="scope">
          <div
            style="max-height: 200px; overflow-y: auto"
            v-html="fmt_content(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column prop="ip" :label="$t('OPERATOR_ID')" width="180" align="left" />
    </el-table>
    <el-pagination
      style="height: 33px"
      class="text-right mt-10"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :page-size="pageSize"
      :current-page="currentPage"
      @size-change="sizeChange"
      @current-change="currentChange"
    />
  </div>
</template>
<script>
  export default {
    props: {
      currentPage: {
        type: Number,
        default: 1
      },
      pageSize: {
        type: Number,
        default: 10
      },
      total: {
        type: Number,
        default: 0
      },
      tableData: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {}
    },
    methods: {
      fmt_content(row) {
        try {
          const content = JSON.parse(row.content)
          return this.$t(content.i18nKey, content).replace(row.userId, (row.realName || row.userId))
        } catch (error) {
          return row.content
        }
      },
      sizeChange(size) {
        this.$emit('update:pageSize', size)
        this.$emit('loadData')
      },
      currentChange(page) {
        this.$emit('update:currentPage', page)
        this.$emit('loadData')
      },
      handleSelectionChange(val) {
        this.$emit('selection-change-event', val)
      }
    }
  }
</script>
<style lang="scss" scoped>
  .table-list > .el-checkbox {
    margin: 5px 20px 15px 0;
    font-size: 12px;
  }
  .table-icon {
    float: right;
    line-height: 23px;
    cursor: pointer;
  }
</style>
